<?php echo $this->doctype(); ?>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/">
    <head>
        <title><?php echo $this->translate('APP_NAME'); ?></title>  
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <!-- CSS Style -->
        <link rel="stylesheet" type="text/css" href="<?php echo STATIC_URL . '/css/ym_canvas_admin.css'; ?>" />
        <link rel="stylesheet" type="text/css" href="<?php echo STATIC_URL . '/css/layout.backend.css'; ?>" />
        <link rel="stylesheet" type="text/css" href="<?php echo STATIC_URL . '/css/canvas.css'; ?>" />
        <link rel="stylesheet" type="text/css" href="<?php echo STATIC_URL . '/css/welcome.css'; ?>" />
        <link rel="shortcut icon" href="<?php echo STATIC_URL.'/images/logo5.png'?>" />
        <!-- Javascript -->
        
        <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
        <script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
        <script type="text/javascript" src="<?php echo STATIC_URL . '/javascript/main.js'; ?>"></script>        
        <script type="text/javascript" src="<?php echo STATIC_URL . '/includes/tiny_mce/tiny_mce.js'; ?>"></script>
        <script type="text/javascript" src="<?php echo STATIC_URL . '/javascript/addmce.js'; ?>"></script>
        <script type="text/javascript" src="<?php echo STATIC_URL . '/javascript/welcome.js'; ?>"></script>
        
	<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/base/jquery-ui.css" type="text/css" media="all" />
		
		<?php echo $this->social->render('initHead'); ?>
		<?php echo $this->headMeta(); ?>
    </head>
    
    <body>
         
		<?php echo $this->social->render('initBody'); ?>
		<div class="ym_body">
            
            <!-- Header -->
			<div class="ym_header">
				<div id="header">
                                        <!-- Left -->
					<div class="ym_header_left">
						<a class="ym_header_logo" href="<?php echo $this->social->getAppUrl() ?>" target="_blank">
							<img src="<?php echo STATIC_URL . '/img/icon/logo.png' ?>" />
						</a>
					</div>
                                        <!-- Left end -->
                                        <!-- Center -->
					<div class="ym_header_center">
                                            <div class="ym_logo_text">
                                                <a href="<?php echo $this->social->getAppUrl() ?>" target="_parent">
                                                    <?php echo $this->translate('APP_NAME')?>
                                                </a>
                                            </div>
                                            <div class="shareUrl">
                                                            <?php echo $this->social->render('like', array(
                                                                    'url'			=> $this->social->getAppUrl(),
                                                                    'send'			=> true,
                                                                    'show_faces'	=> false,
                                                                    'layout'		=> 'standard'
                                                            ));?>
                                            </div>
					</div>
                                        <!-- Center end-->
                                        <!-- Right -->
                                        <div class="ym_header_right">
                                            <div id="public_section" class="swicth_section"></div>
                                            <div class="manage_pages">
                                                
                                            <?php if (count($this->pages) > 0):?>
                                                <select name='id_page' id='id_page'>	
                                                    <option value=''><?php echo $this->translate('SELECT_A_FANPAGE')?></option>		
                                                    <?php if (!empty($this->pages)):?>
                                                        <?php foreach ($this->pages as $page):
                                                            if ($this->id_page == $page['id']):
                                                        ?>
                                                            <option id="id_page_<?php echo $page["id"]?>" value='<?php echo $page['id'];?>' selected="selected"><?php echo $this->escape($page['name']);?></option>
                                                        <?php else:?>
                                                            <option id="id_page_<?php echo $page["id"]?>" value='<?php echo $page['id'];?>'><?php echo $this->escape($page['name']);?>
                                                            </option>	
                                                        <?php
                                                            endif; 
                                                            endforeach;
                                                        ?>		
                                                    <?php endif;?>
                                                </select>
                                               <!-- Config Non-fans page <input type="checkbox" id="ckb_config_non_fans_page"> -->
                                                <span>
                                                    <a id="gotopage" class="view_page button_control greenbutton">
                                                            <?php echo $this->translate('GO')?>                                    
                                                    </a>
                                                </span>
                                                
                                            <?php else:?>
                                                <a id="allow_manage_fanpages" class="button_load_fanpages">
                                                    <span><?php echo $this->translate('LOAD_MY_FANPAGES')?></span>
                                                </a>
                                            <?php endif;?>
					 	</div>
					</div>
				</div>
			</div>
            
            <!-- Container -->
			<div class="ym_container">
                <!-- Top menu -->
				<div class="ym_list_menu">    
                   
                    <?php echo $this->partial('default/admin_top_menu.phtml',array(
                                              'params'  => $this->params,
                                              'id_page' => $this->id_page,
                                              'menu_active' => $this->menu_active,
                                              'social'  => $this->social,
                                              'is_index_config' => $this->is_index_config
                            )) ?> 
				</div>
                <!-- Content -->
				<div class="ym_contents">
                    <div style="padding-left:10px;">
                        <?php echo $this->layout()->content ?>
                    </div>
				</div>
			</div>
            
            <!-- Footer -->
			<div class="ym_footer">
				Powered by <a href="http://media.younetco.com" target="_blank">YouNet Media</a>
			</div> 
		</div>
       
        <script type="text/javascript">	
        var oauth_scope = '<?php echo $this->social->getOAuthScope()?>';

        function initButtonGo()
        {
            var id_page = $("#id_page").val();
            if (id_page != "")
            {
                $("#gotopage").show();
            }
            else
            {
                $("#gotopage").hide();
            }
        }

        initButtonGo();

        $("#id_page").change(function(){
            var id_page = $("#id_page").val();
            var canvasUrl = "<?php echo $this->social->url('/admin/index/config')?>";
            if (id_page != "")
            {
                canvasUrl = canvasUrl + '/id_page/' + id_page;
                isPageInstalled(id_page, function(){
                    top.location = canvasUrl;
                });
            }
            else
            {
                top.location = canvasUrl;
            }
        });

        $("#gotopage").click(function(){
            var page_id = $("#id_page").val();
            var page_name = $("#id_page").find("option:selected").text();

            if (page_id != "")
            { 
                goToPage(page_name, page_id);
            }
            else
            {
                alert("<?php echo $this->translate('PLEASE_SELECT_A_FANPAGE')?>");
            }		
        });

        $("#allow_manage_fanpages").click(function(){
            var redirect_url = "<?php echo $this->social->url('/admin/index/config')?>";
            manageFanpages(redirect_url, oauth_scope);
        });

        var current_page = "<?php echo $this->id_page?>";
        $("#id_page").val(current_page);

        $(".ym_menu a").adjustText({defaultWidth:450});
        </script>
            
            
		<?php echo $this->social->render('autoResize'); ?>
		<?php echo $this->social->render('endBody')?>
        
        
    </body>
</html>